package com.dch.calculator.listeners;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.dch.calculator.R;
import com.dch.calculator.activities.MainActivity;

import java.util.ArrayList;

public class MenuListItemListener implements AdapterView.OnItemClickListener {

    private ArrayList<String> names;
    private Activity activity;

    public MenuListItemListener(final Activity activity, final ArrayList<String> names) {
        this.names = names;
        this.activity = activity;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String name = (String) ((TextView) view).getText();
        if (name == null) {
            return;
        }
        Resources resources = activity.getResources();
        if (names.contains(name)) {
            if (name.equals(resources.getString(R.string.calculator))) {
                ((MainActivity) activity).showCalculator();
            } else if (name.equals(resources.getString(R.string.settings))) {
                ((MainActivity) activity).showSettings();
            } else if (name.equals(resources.getString(R.string.about))) {
                ((MainActivity) activity).showAboutProgram();
            } else {
                activity.finish();
            }
        }
    }
}
